#include "vmode.h"

static VMode::Candidates cans;

static void process(VMode &vm, const char *str)
{
        cans = vm.Decode(str);
        auto cand_type = vm.CandidateType();
        puts("output:");
        printf("\tCand type:%d\n\tComposition:%s\n", cand_type, vm.GetComposition().c_str());
        if(VMode::ET_INVALID != cand_type)
        {
            printf("\tCandidates:");
            for(auto & can : cans)
            {
                printf("%s ", can.c_str());
            }
        }
        putchar('\n');

}

int main(int argc, const char * argv[])
{
    VMode vm;
    if(argc < 2)
    {
        printf("Usage:\n\t%s v1010 C v2025 .1.1 S1 v2025n 1y21r S2 v123456789.0123 S1 v-1 + '2*3' - 10 S1\n", argv[0]);
        printf("Eg:\ninput:%s\n", "v1+\\b-2");
        process(vm, "v1+\b-2");
    }
    for(int i=1; i<argc; i++)
    {
        printf("input:%s\n", argv[i]);
        if(std::string("C") == argv[i])
        {
            printf("Calling Clear\n");
            vm.Clear();
            continue;
        }
        if('S' == *argv[i])
        {
            auto idx = std::atoi(argv[i]+1);
            if(1 || idx > 0 && idx <= cans.size())
            {
                auto commit = vm.Select(idx-1);
                printf("Select:%d\nCommit:%s\n", idx, commit.c_str());
            }
            else
            {
                printf("Invalid input:[%s]\n", argv[i]);
            }
            continue;
        }
        process(vm, argv[i]);
    }
    return 0;
}
